#ifndef F_CAServerC_h
#define F_CAServerC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCAServerSignal { EDROOMSignalTimeout, EDROOMSignalDestroy, SResAck, SResNack, SResReq, SFreeRes };


	friend class CAServer;

	CAServer &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & pService4;
	CEDROOMInterface & pService3;
	CEDROOMInterface & pService2;
	CEDROOMInterface & pService1;

	enum edroomStateId{I, Ready};

	enum IdTrans{Init, FreeSource, ResRequest, ResRequest_Nack, ResRequest_Ack,  EDROOMMEMORIA };

	//Constantes

	const TEDROOMUInt8 VresNumber;


	//Variables

	TEDROOMBool *VresFree;
	TEDROOMUInt8 &VresFreeNumber;


	//Pool

	class CEDROOMPOOLTEDROOMUInt8:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLTEDROOMUInt8(TEDROOMUInt32 elemCount,TEDROOMUInt8 *pMem, TEDROOMBool *pMarks);
		TEDROOMUInt8	* AllocData();
	};
	CEDROOMPOOLTEDROOMUInt8	& EDROOMPoolTEDROOMUInt8;


	// CONSTRUCTORES

	EDROOMTopContext (CAServer &act, TEDROOMBool * EDROOMpVarVresFree, TEDROOMUInt8 & EDROOMpVarVresFreeNumber, CEDROOMPOOLTEDROOMUInt8 & EDROOMpPoolTEDROOMUInt8 );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	void	FAck();

	void	FFreeResource();

	void	FInit();

	void	FNack();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	TEDROOMBool VresFree[2];
	TEDROOMUInt8 VresFreeNumber;


	//Pools

	CEDROOMPOOLTEDROOMUInt8	EDROOMPoolTEDROOMUInt8;


public:

	// CONSTRUCTOR

	EDROOMTopState (CAServer &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Ready

	// ***********************************************************************



	TEDROOMTransId EDROOMReadyllegada();

};


#endif
